﻿using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;

namespace HslCommunication.BasicFramework
{
	/// <summary>
	/// 系统框架支持的一些常用的动画特效
	/// </summary>
	// Token: 0x02000189 RID: 393
	public class SoftAnimation
	{
		/// <summary>
		/// 最小的时间片段
		/// </summary>
		// Token: 0x1700069E RID: 1694
		// (get) Token: 0x06001FFE RID: 8190 RVA: 0x0009C6E3 File Offset: 0x0009A8E3
		// (set) Token: 0x06001FFF RID: 8191 RVA: 0x0009C6EA File Offset: 0x0009A8EA
		private static int TimeFragment { get; set; } = 20;

		/// <summary>
		/// 调整控件背景色，采用了线性的颜色插补方式，实现了控件的背景色渐变，需要指定控件，颜色，以及渐变的时间
		/// </summary>
		/// <param name="control">控件</param>
		/// <param name="color">设置的颜色</param>
		/// <param name="time">时间</param>
		// Token: 0x06002000 RID: 8192 RVA: 0x0009C6F4 File Offset: 0x0009A8F4
		public static void BeginBackcolorAnimation(Control control, Color color, int time)
		{
			bool flag = control.BackColor != color;
			if (flag)
			{
				Func<Control, Color> func = (Control m) => m.BackColor;
				Action<Control, Color> action = delegate(Control m, Color n)
				{
					m.BackColor = n;
				};
				ThreadPool.QueueUserWorkItem(new WaitCallback(SoftAnimation.ThreadPoolColorAnimation), new object[]
				{
					control,
					color,
					time,
					func,
					action
				});
			}
		}

		// Token: 0x06002001 RID: 8193 RVA: 0x0009C78C File Offset: 0x0009A98C
		private static byte GetValue(byte Start, byte End, int i, int count)
		{
			bool flag = Start == End;
			byte result;
			if (flag)
			{
				result = Start;
			}
			else
			{
				result = (byte)((int)(End - Start) * i / count + (int)Start);
			}
			return result;
		}

		// Token: 0x06002002 RID: 8194 RVA: 0x0009C7B4 File Offset: 0x0009A9B4
		private static float GetValue(float Start, float End, int i, int count)
		{
			bool flag = Start == End;
			float result;
			if (flag)
			{
				result = Start;
			}
			else
			{
				result = (End - Start) * (float)i / (float)count + Start;
			}
			return result;
		}

		// Token: 0x06002003 RID: 8195 RVA: 0x0009C7E0 File Offset: 0x0009A9E0
		private static void ThreadPoolColorAnimation(object obj)
		{
			object[] array = obj as object[];
			Control control = array[0] as Control;
			Color color = (Color)array[1];
			int num = (int)array[2];
			Func<Control, Color> func = (Func<Control, Color>)array[3];
			Action<Control, Color> setcolor = (Action<Control, Color>)array[4];
			int count = (num + SoftAnimation.TimeFragment - 1) / SoftAnimation.TimeFragment;
			Color color_old = func(control);
			try
			{
				int j;
				int i;
				for (i = 0; i < count; i = j + 1)
				{
					control.Invoke(new Action(delegate()
					{
						setcolor(control, Color.FromArgb((int)SoftAnimation.GetValue(color_old.R, color.R, i, count), (int)SoftAnimation.GetValue(color_old.G, color.G, i, count), (int)SoftAnimation.GetValue(color_old.B, color.B, i, count)));
					}));
					Thread.Sleep(SoftAnimation.TimeFragment);
					j = i;
				}
				Control control2 = control;
				if (control2 != null)
				{
					control2.Invoke(new Action(delegate()
					{
						setcolor(control, color);
					}));
				}
			}
			catch
			{
			}
		}

		// Token: 0x06002004 RID: 8196 RVA: 0x0009C90C File Offset: 0x0009AB0C
		private static void ThreadPoolFloatAnimation(object obj)
		{
			SoftAnimation.<>c__DisplayClass8_0 CS$<>8__locals1 = new SoftAnimation.<>c__DisplayClass8_0();
			object[] array = obj as object[];
			CS$<>8__locals1.control = (array[0] as Control);
			Control control = CS$<>8__locals1.control;
			bool flag = false;
			try
			{
				Monitor.Enter(control, ref flag);
				SoftAnimation.<>c__DisplayClass8_1 CS$<>8__locals2 = new SoftAnimation.<>c__DisplayClass8_1();
				CS$<>8__locals2.CS$<>8__locals1 = CS$<>8__locals1;
				CS$<>8__locals2.value = (float)array[1];
				int num = (int)array[2];
				Func<Control, float> func = (Func<Control, float>)array[3];
				CS$<>8__locals2.setValue = (Action<Control, float>)array[4];
				CS$<>8__locals2.count = (num + SoftAnimation.TimeFragment - 1) / SoftAnimation.TimeFragment;
				CS$<>8__locals2.value_old = func(CS$<>8__locals2.CS$<>8__locals1.control);
				int j;
				int i;
				for (i = 0; i < CS$<>8__locals2.count; i = j + 1)
				{
					bool flag2 = CS$<>8__locals2.CS$<>8__locals1.control.IsHandleCreated && !CS$<>8__locals2.CS$<>8__locals1.control.IsDisposed;
					if (!flag2)
					{
						return;
					}
					CS$<>8__locals2.CS$<>8__locals1.control.Invoke(new Action(delegate()
					{
						CS$<>8__locals2.setValue(CS$<>8__locals2.CS$<>8__locals1.control, SoftAnimation.GetValue(CS$<>8__locals2.value_old, CS$<>8__locals2.value, i, CS$<>8__locals2.count));
					}));
					Thread.Sleep(SoftAnimation.TimeFragment);
					j = i;
				}
				bool flag3 = CS$<>8__locals2.CS$<>8__locals1.control.IsHandleCreated && !CS$<>8__locals2.CS$<>8__locals1.control.IsDisposed;
				if (flag3)
				{
					CS$<>8__locals2.CS$<>8__locals1.control.Invoke(new Action(delegate()
					{
						CS$<>8__locals2.setValue(CS$<>8__locals2.CS$<>8__locals1.control, CS$<>8__locals2.value);
					}));
				}
			}
			finally
			{
				if (flag)
				{
					Monitor.Exit(control);
				}
			}
		}
	}
}
